import 'package:flutter/material.dart';

class EditTextApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: "表单",
      theme: new ThemeData(primaryColor: Colors.blue),
      home: new EditTextHomePage(),
    );
  }
}

class EditTextHomePage extends StatefulWidget {
  @override
  _EditTextHomePageState createState() => new _EditTextHomePageState();
}

class _EditTextHomePageState extends State<EditTextHomePage> {

  String _lastName;
  String _firstName;
  GlobalKey<FormState> _formKey = new GlobalKey();

  void _showMessage(String name) {
    showDialog(
      context: context,
      builder: (BuildContext context) {
          return new AlertDialog(
        content: new Text(name),
        actions: <Widget>[new FlatButton(onPressed: ()=> Navigator.pop(context), child: new Text("确定"),)]);
      }
    );
  }

  Widget buildInput (FormFieldState<String> field, String label){
    return new Row(
      children: <Widget>[
        new Text(label),
        new TextField()
      ],
    );
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(title: new Text('表单输入')),
      body: new Form(
        child: new Column(
          children: <Widget>[
            new FormField(builder: (FormFieldState<String> field){
              return new Container(
                padding: const EdgeInsets.all(5.0),
                child: new Row(
                  children: <Widget>[
                    new Flexible(
                      child: new TextField(autofocus: true,
                        style: new TextStyle(fontSize: 16.0,color: Colors.black),
                        decoration: new InputDecoration(
                          labelText: '姓氏')
                        )
                    )
                  ],
                ),
              );
            },
            onSaved: (String value)=> _firstName=value),
            new FormField(builder: (FormFieldState<String> field) => new Text('名称'),onSaved: (String value)=> _firstName=value)
          ],
          key: _formKey
        )
      )
    );
  }
}